﻿using Monthly.Framework.BusinessLogic;
using MonthlyDB.Entity;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Page_MonthlyList2 : BaseAuthenticationPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.UseTabber = false;
        if (!IsPostBack)
        {
            if (AppConfig.getUserTypes(CurrentUser.ID).Length == 0)
            {
                Response.Clear();
                Response.Write("无权访问");
                Response.End();
            }
            else
            {
                
            }
        }
    }
    protected DataTable dtMonthlyList
    {
        get
        {
            if (ViewState["dtMonthlyList"] == null)
                ViewState["dtMonthlyList"] = new DataTable();
            return ViewState["dtMonthlyList"] as DataTable;
        }
        set
        {
            ViewState["dtMonthlyList"] = value;
        }
    }
    public Guid DeptID
    {
        get
        {
            Guid gd = Guid.Empty;
            try
            {
                gd = new Guid(Request["ID"] ?? Guid.Empty.ToString());
            }
            catch (System.Exception ex)
            {

            }
            return gd;
        }
       
    }
    private void BindData()
    {
        int recordCount = 0;

        string SearchClauseList = "DeptID='" + DeptID + "'";
        if (tbDateStart.Text != string.Empty)
            SearchClauseList += string.Format("AND {0} >= '{1}'", MonthlyDB.Entity.Monthly.SQLCOL_PUBLISHTIME, tbDateStart.Text);
        if (tbDateEnd.Text != string.Empty)
            SearchClauseList += string.Format(" AND {0}<=N'{1}'", MonthlyDB.Entity.Monthly.SQLCOL_PUBLISHTIME, tbDateEnd.Text);
        if (tbFileName.Text != string.Empty)
            SearchClauseList += string.Format(" AND {0} LIKE N'%{1}%'", MonthlyDB.Entity.Monthly.SQLCOL_FILENAME, tbFileName.Text.Replace("'", "''").Replace("%", "[%]"));



        pager1.RecordCount = recordCount;
        rptFiles.DataSource = BLMonthly.GetMonthlyList(SearchClauseList, pager1.PageIndex, pager1.PageSize, string.Format("{0} {1}", "CreateTime", "Desc"), ref recordCount);
        pager1.RecordCount = recordCount;
        rptFiles.DataBind();
    }

    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        BindData();
    }


    protected void btnAdvancedSearch_Click(object sender, EventArgs e)
    {

        pager1.PageIndex = 0;
        BindData();
    }
    protected void lbtnDelete_Click(object sender, EventArgs e)
    {

        BLMonthly.DeleteMonthlys(hfIDs.Value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries));

        pager1.PageIndex = 0;
        BindData();
    }
    protected void pager_PreRender(object sender, EventArgs e)
    {
        BindData();
    }
    public string Cut(object title, int length)
    {
        if (title != null)
        {
            string _title = title.ToString();
            return _title.Length > length ? (_title.Substring(0, length) + "...") : _title;
        }
        return string.Empty;
    }
}